package main

import (
	"auto-login/login"
	"fmt"
	"os/exec"
	"time"
)

const (
	tryMaxTimes = 5
	tryInterval = 5 * time.Second
)

func NetWorkStatus() bool {
	cmd := exec.Command("ping", "baidu.com", "-c", "1", "-W", "5")
	err := cmd.Run()
	if err != nil {
		fmt.Println(err.Error())
		return false
	} else {
		fmt.Println("Net Status , OK")
	}
	return true
}

func main() {
	for i := 0; i < tryMaxTimes; i++ {
		if !NetWorkStatus() {
			login.LoginFromJson()
		} else {
			return
		}
		time.Sleep(tryInterval)
	}
	panic("try online but all failed!\n")
}
